import { useEffect, useRef } from 'react'

const Demo5 = () => {
  // 引用DOM节点
  const inputRef = useRef(null)
  useEffect(() => {
    inputRef.current.focus()
  }, [])

  const setInputValue = () => {
    inputRef.current.value = '哈哈哈哈'
  }

  return (
    <>
      <h3>Demo5</h3>
      <input type="text" placeholder="输入" ref={inputRef} />
      <button onClick={setInputValue}>设置input值</button>
    </>
  )
}

export default Demo5
